import { http } from '@/utils/http'
import type { GoodsSkuCartVo, GoodsCart } from './cart.d'

/** 获取购物车列表 */
export const getCartList = (params: { current?: number; size?: number }) => {
  return http<PageResult<GoodsSkuCartVo>>({
    url: '/goods/cart/list',
    query: params,
    method: 'GET',
  })
}
/** 获取购物车全部购物车数据 */
export const getCartAllList = () => {
  return http<GoodsSkuCartVo[]>({
    url: '/goods/cart/all/list',
    method: 'GET',
  })
}
/** 根据ids获取购物车数据 */
export const getCartListByIds = (ids: number[]) => {
  return http<PageResult<GoodsSkuCartVo>>({
    url: `/goods/cart/${ids}`,
    method: 'GET',
  })
}
/** 添加购物车 */
export const addCart = (data: GoodsCart) => {
  return http<number>({
    url: '/goods/cart/add',
    data,
    method: 'POST',
  })
}

/** 更新购物车 */
export const updateCart = (data: GoodsCart) => {
  return http<boolean>({
    url: '/goods/cart/update',
    data,
    method: 'POST',
  })
}

/** 删除单个购物车项 */
export const deleteCart = (id: number) => {
  return http<boolean>({
    url: `/goods/cart/delete/${id}`,
    method: 'DELETE',
  })
}

/** 清空购物车 */
export const deleteCartAll = () => {
  return http<boolean>({
    url: '/goods/cart/delete/all',
    method: 'DELETE',
  })
}

/** 批量删除购物车 */
export const deleteCartBatch = (ids: number[]) => {
  return http<boolean>({
    url: '/goods/cart/delete/batch',
    query: { ids: ids.join(',') },
    method: 'DELETE',
  })
}
